package com.tarena.csmall.filters.filter;

import java.io.IOException;
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import org.springframework.web.filter.OncePerRequestFilter;

/*
只要spring容器中有一个实现Filter接口的bean
就会在springmvc中生效过滤器
每次请求,必定经过这个过滤器
 */
@Component
@Order(2)
public class MyFilter02 extends OncePerRequestFilter {

    @Override protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response,
        FilterChain filterChain) throws ServletException, IOException {
        System.out.println("MyFilter02.doFilterInternal,请求进入");
        //放行之前是请求进入的过程
        filterChain.doFilter(request,response);//过滤器放行
        //放行之后是响应出去的过程
        System.out.println("MyFilter02.doFilterInternal响应返回");
    }
}
